package com.enterprise.domain;

public class Page {
	private int pageSize;//每页显示的条数
	private int recordCount;//总共的条数
	private int currentPage;//当前页面
	public Page(int pageSize,int recordCound,int currentPage){
		this.pageSize=pageSize;
		this.recordCount=recordCound;
		setCurrentPage(currentPage);
	}
	
	/**
	 * 默认从第一页开始
	 * @param pageSize
	 * @param recordCount
	 */
	 public Page(int pageSize, int recordCount){ 
         this(pageSize, recordCount, 1); 
     } 
	 /**
	  * 总页数
	  * @return
	  */
	 public int getPageCount(){
		 int size=recordCount/pageSize;//总条数/每页显示的条数=总页数
		 int mod=recordCount%pageSize;//最后一页的条数
		 if(mod!=0)
			 size++;
		 return recordCount==0?1:size;
	 }
	 /**
	  * 从索引0开始
	  * @return
	  */
	 public int getFromIndex(){
		 return (currentPage-1)*pageSize;
	 }
	 
	 public int getToIndex(){
		 return Math.min(recordCount, currentPage*pageSize);
	 }
	 
	 public int getCurrentPage(){
		 return currentPage;
		 
	 }
	 /**
	  * 设置当前页面
	  * @param currentPage
	  */
	 public void setCurrentPage(int currentPage){
		 int validPage=currentPage<=0?1:currentPage;
		 validPage=validPage>getPageCount()?getPageCount():validPage;
		 this.currentPage=validPage;
	 }
	 /**
	  * 获取每页显示的条数
	  * @return
	  */
	 public int getPageSize(){
		 return pageSize;
	 }
	 
	  public void setPageSize(int pageSize){ 
          this.pageSize = pageSize; 
      }//得到总共的条数 
      public int getRecordCount(){ 
          return recordCount; 
      }//设置总共的条数 
      public void setRecordCount(int recordCount){ 
          this.recordCount = recordCount; 
      } 
}
